<template>
	<om-page>
		<view class="show-table-head padding-left padding-top-xs om_hd_fix">
			<view class="margin-xs workhour-cache-info-user-name">
				{{userName}}
			</view>
		</view>
		<uni-list v-if="tableData.length" class="show-table-list">
			<uni-list-item v-for="(item,index) of tableData" :key="index" 
				:avatar="index + 1"
				:title="item.posName || item.eduEName || item.appellationFName || item.changeItem"
				:avatarBgColor="calcBgColor(item)"
				@click="toInfo(index)"
				class="tableData-item">
				<view slot="note">
					<view class="" v-for="(titleItem,titleIndex) of tableTitle" :key="titleIndex">
						<view v-if="titleIndex<5 && hasField(titleItem.field)">
							{{titleItem.title + ' : '+ deleteHtml((item[titleItem.field] || ''))}}
						</view>
					</view>
				</view>
			</uni-list-item>
		</uni-list>
	</om-page>
</template>

<script>
	import { ignoreHtml } from '@/static/js/common.js';
	export default{
		data(){
			return {
				tableTitle:[],
				tableData:[],
				mark:'',
				page: 1,
				rows: 20,
				userId:'',
				userName:'',
				title:'',
				exsitList:[
					'posName',
					'eduEName',
					'appellationFName',
					'changeItem'
				]
			}
		},
		computed:{
			deleteHtml(){
				return function(val){
					return ignoreHtml(val)
				}
			},
			calcBgColor() {
				return function(){
					return this.ColorList[3].name
				} 
			},
			hasField(){
				return function(title){
					for(let titleIndex in this.exsitList){
						if(title == this.exsitList[titleIndex]){
							return false
						}
					}
					return true
				}
			}
		},
		methods:{
			getRequest(){
				let _that = this
				if(_that.mark == 'KEY_90'){
					return(_that.om.request(
						"temployee/getEduDgData",
						{
							page:_that.page,
							rows:_that.rows,
							'userId':_that.userId,
						},
						'get',true
					))
				}else if(_that.mark == 'KEY_89'){
					return(_that.om.request(
						"orgInstPosUserOfficial/datagrid",
						{
							page:_that.page,
							rows:_that.rows,
							'user.id':_that.userId
						},
						'get',true
					))
				}else if(_that.mark == 'KEY_91'){
					return(_that.om.request(
						"temployee/getAppendixDg",
						{
							'userId':_that.userId
						},
						'get',true
					))
				}else if(_that.mark == 'KEY_92'){
					return(_that.om.request(
						"temployee/getWorkDgData",
						{
							page:_that.page,
							rows:_that.rows,
							'userId':_that.userId
						},
						'get',true
					))
				}else if(_that.mark == 'KEY_93'){
					return(_that.om.request(
						"temployee/getFamilyDgData",
						{
							page:_that.page,
							rows:_that.rows,
							'userId':_that.userId
						},
						'get',true
					))
				}else if(_that.mark == 'KEY_94'){
						return(_that.om.request(
							"temployee/getInfoHistoryDgData",
							{
								page:_that.page,
								rows:_that.rows,
								'userId':_that.userId
							},
							'get',true
						))
				}else if(_that.mark == 'KEY_107'){
						return(_that.om.request(
							"temployee/getSalaryDgData",
							{
								page:_that.page,
								rows:_that.rows,
								'userId':_that.userId
							},
							'get',true
						))
				}else if(_that.mark == 'KEY_181'){
						return(_that.om.request(
							"userRewardList/getDataGrid",
							{
								page:_that.page,
								rows:_that.rows,
								'userId':_that.userId
							},
							'get',true
						))
				}else if(_that.mark == 'KEY_181'){
						return (_that.om.request(
							"userRewardList/getDataGrid",
							{
								page:_that.page,
								rows:_that.rows,
								'userId':_that.userId
							},
							'get',true
						))
				}else if(_that.mark == 'KEY_358'){
						return(_that.om.request(
							"trainUserShow/getCenterTrainData",
							{
								page:_that.page,
								rows:_that.rows,
								'userId':_that.userId
							},
							'get',true
						))
				}else if(_that.mark == 'KEY_359'){
					return(_that.om.request(
						"temployee/getEmpEvaluateCount",
						{
							page:_that.page,
							rows:_that.rows,
							'userId':_that.userId
						},
						'get',true
					))
				}
			},
			toInfo(index){
				let _that = this
				uni.setStorage({
					key:'temployeeInfoTitleCache',
					data:_that.tableTitle
				})
				uni.setStorage({
					key:'temployeeInfoDataCache',
					data:_that.tableData[index]
				})
				uni.navigateTo({
					url:'./temployee-info?title='+(_that.title+'详情')+'&userId='+_that.userId+'&posId='+_that.tableData[index].posId,
				})
			},
			initLoad(){
				let _that = this
				let arr = [
					_that.om.request(
						"ttableColumn/getGridModel",
						{
							tableMark: _that.mark,
							ignores:_that.mark == 'KEY_358'? 'trainEvaluationUserId,shouldPartakeNum,leaveNum,truancyNum,subCheckInNum,lateNum,assessmentResultName,trainResultName,scoreNum,remark':''
						},
						'get',true
					),
				]
				 arr.push(this.getRequest())
				 uni.showLoading({
				 	mask: true,
				 	title: '请稍候...'
				 })
				Promise.all(arr).then(res=>{
					let arr = res[0].value.columns[0].map(e=>e)
					_that.tableTitle = arr
					_that.tableData = res[1].rows || res[1]
					uni.hideLoading()
				})
			}
		},
		onLoad(e) {
			let _that = this
			_that.mark = e.mark
			_that.userId = e.userId
			_that.title =  e.title
			_that.userName = e.userName
			uni.setNavigationBarTitle({
				title: e.title
			})
			_that.initLoad()
		},
		onReachBottom(){
			if(this.tableData.length%this.rows== 0){
				this.page += 1 
				this.getRequest().then(res=>{
					this.tableData.push(...res.rows)
				})
			}
		}
	}
</script>

<style scoped>
	.tableData-item{
		font-size: 12px;
	}
	.show-table-head{
		background-color: white;
	}
	.show-table-list{
		margin-top: 34px;
	}
</style>                                                  
